import java.awt.*;

public class Wall {
	int x, y, w, h;
	TankClient tc;
	private int life = 100;
	private boolean needRemove = false;

	public Wall(int x, int y, int w, int h, TankClient tc) {
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
		this.tc = tc;
	}

	public void draw(Graphics g) {
		if (needRemove) return;

		Color c = g.getColor();
		g.setColor(Color.DARK_GRAY);
		g.fillRect(x, y, w, h);

		g.setColor(Color.RED);
		g.drawRect(x, y - 10, w, 10);
		int barWidth = w * life / 100;
		g.fillRect(x, y - 10, barWidth, 10);

		g.setColor(c);
	}

	public Rectangle getRect() {
		return new Rectangle(x, y, w, h);
	}

	public void hitByMissile() {
		life -= 20;
		if (life <= 0) {
			needRemove = true;
			AudioUtil.playExplodeSound();
			tc.wallExplodes.add(new WallExplode(x, y, w, h, tc));
		}
	}

	public boolean isNeedRemove() {
		return needRemove;
	}

	public int getLife() {
		return life;
	}
}